#!coding=utf-8
import time
import threading

# 创建一个条件变量
condition = threading.Condition()

def worker1():
    with condition:
        # 等待条件成立
        condition.wait()
        # 访问共享数据
        print("Worker 1 is working...")

def worker2():
    with condition:
        # 等待条件成立
        condition.wait()
        # 访问共享数据
        print("Worker 2 is working...")

def worker3():
    with condition:
        # 访问共享数据
        print("Worker 3 is working...")

        time.sleep(3)
        # 通知其他线程条件已经成立
        # condition.notify()
        # condition.notify()
        condition.notify_all()

# 创建两个线程
thread1 = threading.Thread(target=worker1)
thread2 = threading.Thread(target=worker2)
thread3 = threading.Thread(target=worker3)

# 启动线程
thread1.start()
thread2.start()
thread3.start()

# 等待所有线程结束
thread1.join()
thread2.join()
thread3.join()